Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Yes by Ctrl+C on Terminate batch job (Y/N)? on Windows #450

Merged
merged 2 commits into from
Oct 28, 2023

Conversation

o-sdn-o
Copy link
Collaborator

@o-sdn-o o-sdn-o commented Oct 28, 2023

xlink microsoft/terminal#217

At least, it it possible to make the second Ctrl+C act as Y when CMD is already asking Terminate batch job (Y/N)?

The question is not for me, but it also concerns me. This is a COOKED_READ territory, not cmd.exe.

The Terminate batch job (Y/N)? call is represented in the system as <noalias> (this is its exe name), so the input for it can be altered using doskey macro. To be sure, try the following example (run test1.cmd, press Ctrl+C, and press n):

test1.cmd:

@echo off
doskey /exename=^<noalias^> n=y
echo About to do it.
pause
echo test

The next test works in WT on Windows10 but does not work directly in conhost:

test2.cmd:

@echo off
doskey /exename=^<noalias^> �=y
echo About to do it.
pause
echo test

The doskey /exename=^<noalias^> �=y command contains ASCII character with code 0x03 (ETX, Ctrl+C). It can be inserted to the test2.cmd using for example Notepad++ by typing text 03, select it, and apply plugin Plugins->Converter->HEXtoASCII.

Perhaps you can think through this idea and come up with a full-fledged workaround.

Anyway, it is possible to handle Ctrl+C keypress per exe-name (e.g. =<noalias>) as a special (may be configurable) case, and do not touching cmd.exe itself.

UPDATE: Now you could try how it works in vtm without any doskey shims (tested and works fine on Win8/Win10/Win11/Server2019Core/Server2019/Server2022 (including localized))

Command.Prompt.-.cmd.2023-10-28.20-11-06.mp4

UPDATE2: It has a small side effect on copy/move/del commands (perhaps we must filter it by looking at the last key pressed != Ctrl+C)

C:\Users\sdn>copy con iii 
^Z 
        1 file(s) copied.

C:\Users\sdn>copy iii ooo 
        1 file(s) copied.

C:\Users\sdn>copy iii ooo
Overwrite ooo? (Yes/No/All): (Ctrl+C = Y) n 
        0 file(s) copied.

C:\Users\sdn>move iii ooo 
Overwrite C:\Users\sdn\ooo? (Yes/No/All): (Ctrl+C = Y) n 
        0 file(s) moved.

C:\Users\sdn>mkdir ppp 

C:\Users\sdn>del ppp 
C:\Users\sdn\ppp\*, Are you sure (Y/N)? (Ctrl+C = Y) n 

C:\Users\sdn> 

UPDATE3: Interference with copy/move/del has been eliminated:

D:\sources\test\cmd>copy iii ooo 
Overwrite ooo? (Yes/No/All): ^C 

        0 file(s) copied.

D:\sources\test\cmd>move iii ooo 
Overwrite D:\sources\test\cmd\ooo? (Yes/No/All): ^C 

        0 file(s) moved.

D:\sources\test\cmd>del ppp 
D:\sources\test\cmd\ppp\*, Are you sure (Y/N)? ^C 

D:\sources\test\cmd>test 
About to do it.
Press any key to continue . . . 
Terminate batch job (Y/N)? (Ctrl+C = Y) y 
^C
D:\sources\test\cmd> 

@o-sdn-o o-sdn-o merged commit 70ef8f8 into directvt:master Oct 28, 2023
9 checks passed
@o-sdn-o o-sdn-o deleted the vt-input-mode branch October 28, 2023 15:15
o-sdn-o added a commit to o-sdn-o/vtm that referenced this pull request Oct 28, 2023
o-sdn-o added a commit to o-sdn-o/vtm that referenced this pull request Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant